
package system;


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;

import java.awt.Dimension;
import java.awt.GridLayout;

@SuppressWarnings("serial")
public class AddCalendar extends JPanel {
	
	

    public AddCalendar() {
        super(new GridLayout(1,0));

        JTable table = new JTable(new MyTableModel());
        table.setPreferredScrollableViewportSize(new Dimension(400, 70));
        table.setFillsViewportHeight(true);


        JScrollPane scrollPane = new JScrollPane(table);
        
        TableColumn column = null;
        	
        
        	column = table.getColumnModel().getColumn(0);
        
        	column.setPreferredWidth(300);
     
            column = table.getColumnModel().getColumn(1);
 
            column.setPreferredWidth(100);



        add(scrollPane);
    }

    class MyTableModel extends AbstractTableModel {
        private String[] columnNames = {"Navn",
                                        "Vis"};
        private Object[][] data = {
	    {"Erlend Heimark",new Boolean(false)},
	    {"Nina Rippmann", new Boolean(false)},
	    {"Marius Haugen", new Boolean(true)}
        };

        public int getColumnCount() {
            return columnNames.length;
        }

        public int getRowCount() {
            return data.length;
        }

        public String getColumnName(int col) {
            return columnNames[col];
        }

        public Object getValueAt(int row, int col) {
            return data[row][col];
        }

        @SuppressWarnings({ "unchecked", "rawtypes" })
		public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }

        public boolean isCellEditable(int row, int col) {

            if (col < 2) {
                return false;
            } else {
                return true;
            }
        }

        public void setValueAt(Object value, int row, int col) {
            data[row][col] = value;
            fireTableCellUpdated(row, col);
        }

    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("Legg til kalender");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        AddCalendar newContentPane = new AddCalendar();
        newContentPane.setOpaque(true);
        frame.setContentPane(newContentPane);

 
        frame.pack();
        frame.setVisible(true);
    }
       
}